package hasthi.container.p2p;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import org.apache.xmlbeans.XmlObject;
import org.w3.x2003.x05.soapEnvelope.EnvelopeDocument;

import rice.p2p.commonapi.Id;
import rice.p2p.commonapi.rawserialization.OutputBuffer;
import rice.p2p.commonapi.rawserialization.RawMessage;

public class UnicastXmlMessage extends XmlMesssage implements RawMessage{
    private static final long serialVersionUID = 1365310073726197180L;

    public UnicastXmlMessage(EnvelopeDocument envelope) {
        super(envelope);
    }

    public UnicastXmlMessage(XmlObject message, Id senderID, String soapAction) {
        super(message, senderID, soapAction);
    }

    public int getPriority() {
        return 0;
    }

    public short getType() {
        return 15;
    }

    public void serialize(OutputBuffer outbuffer) throws IOException {
        ByteArrayOutputStream outstream = new ByteArrayOutputStream();
        envelope.save(outstream);
        outstream.flush();
        byte[] dataAsBytes = outstream.toByteArray();
        outbuffer.write(dataAsBytes, 0, dataAsBytes.length);
    }
}

